﻿using GameStructure.Contracts;
using GameStructure.Core;
using GameStructure.Types;
using GameStructure.Utilities;
using Tao.OpenGl;

namespace GameStructure.GaneState
{
    public class FPSTestState : IGameObject
    {
        private readonly Font _font;
        private Text _fpsText;
        private readonly Renderer _renderer = new Renderer();
        private readonly FramesPerSecond _fps = new FramesPerSecond();

        public FPSTestState(TextureManager textureManager)
        {
            _font = new Font(textureManager.Get("font"), FontParser.Parse(@"Resources\font.fnt"));
            _fpsText = new Text("FPS:", _font);
        }

        public void Update(double elapsedTime)
        {
            _fps.Process(elapsedTime);
        }

        public void Render()
        {
            Gl.glClearColor(0.0f,0.0f,0.0f,1.0f);
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
            _fpsText = new Text("FPS: " + _fps.CurrentFPS.ToString("00.0"), _font);
            _renderer.DrawText(_fpsText);

            // Uncomment this to render around 10,000 quads
            // Note the FPS change.
            for (var i = 0; i < 1000; i++)
            {
                _renderer.DrawText(_fpsText);
            }
            _renderer.Render();
        }
    }
}
